import os
import hashlib


def get_filehash(path):
    """获取文件hash"""
    with open(path, 'rb') as fp:
        BYTES = fp.read()
        return hashlib.md5(BYTES).hexdigest() if os.path.isfile(path) else ''


def allowed_file_extension(filename):
    """检查文件后缀是否合法"""
    extensions = tuple(['.pdf', '.PDF', '.jpg', '.jpeg', '.png', '.bmp'])
    return filename.endswith(extensions)
